<template>
  <div>
    <el-container>
      <el-header style="margin: 0 auto">
        <!--            <h1>物资操作流水记录</h1>-->
        <label style="color: darkturquoise;font-weight: bolder;font-size: larger;text-align: center">员工留言信息列表</label>
      </el-header>
    </el-container>
    <!--      <el-button @click="resetDateFilter">清除日期过滤器</el-button>-->
    <!--      <el-button @click="clearFilter">清除所有过滤器</el-button>-->
    <el-card>
      <el-table ref="filterTable" :data="tableData" style="width: 100%">
        <el-table-column prop="time" label="日期" sortable width="180" column-key="date">
        </el-table-column>
        <el-table-column prop="title" label="标题" width="180">
        </el-table-column>
        <el-table-column prop="content" label="内容" :formatter="formatter"></el-table-column>
        <el-table-column prop="status" label="状态" width="180"
                         :filters="[{ text: '未读', value: 0 }, { text: '已读', value: 1 }]" :filter-method="filterTag"
                         filter-placement="bottom-end">
          <template slot-scope="scope">
            <el-button style="margin-right: 10px" type="warning" size="mini"
                       @click="deleteMessage(scope.row)">删除</el-button>

          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-row>
      <el-col :span="12" :offset="12">
        <el-pagination layout="total,prev, pager, next,jumper,sizes " background small prev-text="上一页" next-text="下一页"
                       :total="total" :page-size="pageSize" :current-page="pageNow" :page-sizes="[10, 20, 50]" style="margin:15px 0px"
                       @current-change="findPage" @size-change="findSize">
        </el-pagination>
      </el-col>
    </el-row>
    <!--      个人信息展示-->
    <el-dialog title="消息详情" :visible.sync="msgDetailShow">
      <!-- <div>物资类型展示</div> -->
      <!-- <UserDetailVue></UserDetailVue>    -->
      <div>
        <el-descriptions class="margin-top" title="属性列表" :column="1" :size="size" border>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-user"></i>
              标题
            </template>
            {{ messageDetail.title }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-user"></i>
              留言人员
            </template>
            <!--              {{ messageDetail.userId }}-->
            {{ messageDetail.user.name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-mobile-phone"></i>
              详情
            </template>
            {{ messageDetail.content }}
          </el-descriptions-item>
        </el-descriptions>
      </div>

    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'messageManagement',
  data() {
    return {
      pageNow: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      msgDetailShow: false,
      size: '',
      messageDetail: {
        user: 'medium'
      }
    };
  },

  mounted() {
    this.getMsgList()
    // this.$bus.$on("getMsgList",this.refreshMsg)
  },
  beforeDestroy() {
    // this.$bus.$off("getMsgList")
  },

  methods: {
    refreshMsg(){
      console.log("子页面接收到消息了")
      this.getMsgList()
    },
    deleteMessage(row) {
      // console.log(row)
      this.$http.delete("/message/delete/" + row.id).then(res => {
        // row.user = res.data.data
        this.$message({
          message: res.data.data,
          type: 'success'
        });
        this.getMsgList()
      });
      this.getMsgList()
    },
    //改变页码数据量大小
    findSize(size) {
      this.pageSize = size
      this.getMsgList()
    },
    changeMsgStatus(mid) {
      this.$http.put("/message/status/" + mid).then(res => {
        // console.log(res.data)
      });
      this.getMsgList()
    },
    findPage(page) {
      this.pageNow = page
      this.getMsgList()

    },
    //获取消息列表
    getMsgList() {
      this.$http.get("/message/list/" + this.pageNow + "/" + this.pageSize).then(res => {
        // console.log(res.data)
        this.tableData = res.data.data.records
        this.total = res.data.data.total
      })
    },


    formatter(row, column) {
      return row.content;
    },
    filterTag(value, row) {
      return row.status === value;
    },
    filterHandler(value, row, column) {
      const property = column['property'];
      return row[property] === value;
    }
  },
};
</script>

<style lang="less" scoped></style>
